from django.shortcuts import render, HttpResponse
from rest_framework.response import Response
from rest_framework.views import APIView
from api import models
from rest_framework import serializers

# ModelSerializer
class DepartSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.Depart
        # fields = "__all__"
        # 指定字段
        fields = ["title", "count"]

class DepartView(APIView):
    def get(self, request, *args, **kwargs):
        # 单个
        # depart_object = models.Depart.objects.all().first()
        # 多个
        query_set = models.Depart.objects.all()

        ser = DepartSerializer(instance=query_set, many=True)
        return Response(ser.data)


